'use strict';
exports.main = async (event, context) => {
	//event为客户端上传的参数
	const db = uniCloud.database({});
	const shop = db.collection('db_shop_bag')
	let dd = [];
	console.log(event.item_id, event.type, 123)
	await shop.aggregate().match({
		uid: event.item_id,
		type: event.type
	}).lookup({
		from: 'db_shop',
		localField: 'item_id',
		foreignField: 'item_id',
		as: 'shop'
	}).end().then((res) => {
		dd = res.data
		for (let i = 0; i < dd.length; i++) {
			dd[i]["img"] = dd[i]["shop"][0]["item_img"]
			dd[i]["title"] = dd[i]["shop"][0]["item_title"]
			dd[i]["content"] = dd[i]["shop"][0]["item_content"]
			dd[i]["price"] = dd[i]["shop"][0]["item_price"]
			dd[i]["id"] = dd[i]["shop"][0]["_id"]
			dd[i]["item_shops"] = dd[i]["shop"][0]["item_shops"]
			dd[i]["flat"] = false

		}
	})
	console.log(dd, 123)

	return dd
	// .lookup({
	// from: 'student',
	// localField: 'id',
	// foreignField: 'class_id',
	// as: 'stu'
	// })
	// .match({
	// teacher:"徐老师"
	// })
	// .end()
	//返回数据给客户端
};